#!/bin/bash

# Create base directories
declare -a dirs=(
    "config"
    "modules/base"
    "modules/chat"
    "modules/translation"
    "modules/text"
    "modules/image"
    "modules/voice"
    "utils"
    "services"
    "web/templates/components"
    "web/static/css"
    "web/static/js"
    "web/static/assets"
    "web/static/images"
    "tests/unit"
    "tests/integration"
    "docs/api"
    "docs/development"
    "docs/faq"
    "cache/models"
    "logs"
)

# Create directories
for dir in "${dirs[@]}"; do
    mkdir -p "$dir"
    echo "Created directory: $dir"
done

# Create Python package files
declare -a init_files=(
    "config/__init__.py"
    "modules/__init__.py"
    "modules/base/__init__.py"
    "modules/chat/__init__.py"
    "modules/translation/__init__.py"
    "modules/text/__init__.py"
    "modules/image/__init__.py"
    "modules/voice/__init__.py"
    "utils/__init__.py"
    "services/__init__.py"
    "tests/__init__.py"
    "tests/unit/__init__.py"
    "tests/integration/__init__.py"
)

# Create __init__.py files
for init in "${init_files[@]}"; do
    touch "$init"
    echo "Created: $init"
done

# Create module files
declare -a module_files=(
    # Base module
    "modules/base/base_model.py"
    "modules/base/exceptions.py"
    # Chat module
    "modules/chat/chat_model.py"
    "modules/chat/memory.py"
    # Translation module
    "modules/translation/translator.py"
    "modules/translation/language_detector.py"
    # Text module
    "modules/text/generator.py"
    "modules/text/summarizer.py"
    # Image module
    "modules/image/text_to_image.py"
    # Voice module
    "modules/voice/voice_clone.py"
    "modules/voice/tts.py"
    "modules/voice/stt.py"
)

# Create module files
for module in "${module_files[@]}"; do
    touch "$module"
    echo "Created: $module"
done

# Create utility files
declare -a util_files=(
    "utils/logger.py"
    "utils/validators.py"
    "utils/decorators.py"
    "utils/constants.py"
)

# Create utility files
for util in "${util_files[@]}"; do
    touch "$util"
    echo "Created: $util"
done

# Create service files
declare -a service_files=(
    "services/model_manager.py"
    "services/api_service.py"
    "services/cache_service.py"
)

# Create service files
for service in "${service_files[@]}"; do
    touch "$service"
    echo "Created: $service"
done

# Create test files
declare -a test_files=(
    "tests/unit/test_chat.py"
    "tests/unit/test_translation.py"
    "tests/unit/test_model_manager.py"
    "tests/integration/test_api.py"
    "tests/integration/test_web.py"
)

# Create test files
for test in "${test_files[@]}"; do
    touch "$test"
    echo "Created: $test"
done

# Create web files
declare -a web_files=(
    "web/templates/base.html"
    "web/templates/components/chat.html"
    "web/templates/components/translation.html"
    "web/static/css/main.css"
    "web/static/js/app.js"
)

# Create web files
for web in "${web_files[@]}"; do
    touch "$web"
    echo "Created: $web"
done

# Create documentation files
declare -a doc_files=(
    "docs/README.md"
    "docs/api/README.md"
    "docs/development/README.md"
    "docs/faq/README.md"
)

# Create documentation files
for doc in "${doc_files[@]}"; do
    touch "$doc"
    echo "Created: $doc"
done

# Create root level files
declare -a root_files=(
    "app.py"
    "requirements.txt"
    "setup.py"
    "pytest.ini"
    ".env.example"
    "docker-compose.yml"
    "Dockerfile"
)

# Create root level files
for root in "${root_files[@]}"; do
    touch "$root"
    echo "Created: $root"
done

# Create config files
touch "config/settings.py"
touch "config/secrets.json"

# Create .gitignore if it doesn't exist
if [ ! -f .gitignore ]; then
    cat > .gitignore << EOL
# Python
__pycache__/
*.py[cod]
*$py.class
*.so

# Distribution / packaging
dist/
build/
*.egg-info/

# Virtual environments
venv/
env/
ENV/
.env
.venv

# IDE
.idea/
.vscode/
*.swp
*.swo

# Logs and databases
*.log
*.sqlite3
logs/

# Config and secrets
config/secrets.json
.env
.env.local

# Cache
cache/
.cache/

# Test coverage
.coverage
htmlcov/
.pytest_cache/

# Documentation
docs/_build/

# Dependencies
node_modules/

# Compiled files
*.pyc
*.pyo
*.pyd
.Python
*.class

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
EOL
    echo "Created: .gitignore"
fi

echo "Project structure created successfully!" 